package com.lw.enums;

/**
 * Created by IntelliJ IDEA
 *
 * @Author L1W31
 * @Date 2021/8/4 21:00
 * @Version 1.0
 * @Description 使用枚举表示常量数据字段
 */
public enum SecKillStateEnum {

    SUCCESS(1, "秒杀成功"),
    END(0, "秒杀结束"),
    REPEAT_KILL(-1, "重复秒杀"),
    INNER_ERROR(-2, "系统异常"),
    DATA_REWRITE(-3, "数据篡改");

    private int state;

    private  String StateInfo;

    SecKillStateEnum(int state, String stateInfo) {
        this.state = state;
        StateInfo = stateInfo;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getStateInfo() {
        return StateInfo;
    }

    public void setStateInfo(String stateInfo) {
        StateInfo = stateInfo;
    }

    /**
    * @Description:
    * @Param: [index]
    * @return:
    */
    public static SecKillStateEnum stateOf(int index) {
        for (SecKillStateEnum state : values()) {
            if (state.getState() == index) {
                return state;
            }
        }
        return null;
    }
}
